package cn.metafoo.common.exception;

import cn.metafoo.common.entity.ErrorCode;
import cn.metafoo.common.exception.enums.ApiErrorCodeRange;
import lombok.*;

/**
 * 业务逻辑异常 Exception
 *
 * @Author: fatto
 * @create: 2023/3/23 14:27
 */
@Data
@NoArgsConstructor
@AllArgsConstructor
@EqualsAndHashCode(callSuper = true)
public class ApiException extends RuntimeException {

    /**
     * 全局错误码
     *
     * @see ApiErrorCodeRange
     */
    @Getter
    private Integer code;
    /**
     * 错误提示
     */
    @Getter
    private String message;

    public ApiException(ErrorCode errorCode) {
        this.code = errorCode.getCode();
        this.message = errorCode.getMsg();
    }

    public ApiException setCode(Integer code) {
        this.code = code;
        return this;
    }

    public ApiException setMessage(String message) {
        this.message = message;
        return this;
    }
}
